﻿Public Class NhanVienDAO
    Private connect As Connect
    Private sqlstr As String
    Public Sub New()
        connect = New Connect
    End Sub
    Public Function CapNhat(ByVal emp As NhanVienDTO, ByVal flag As Boolean)
        Dim manv As String = emp.MaNhanVien
        Dim tennv As String = emp.TenNhanVien
        Dim diachi As String = emp.DiaChiNhanVien
        Dim sodt As String = emp.DienThoaiNhanVien

        '-------------------------------------------'
        If flag = True Then
            sqlstr = "INSERT NHANVIEN (MaNhanVien, TenNhanVien, DiaChiNhanVien, DienThoaiNhanVien)" & _
                        " VALUES('" & manv & "', '" & tennv & "', '" & _
                                        diachi & "', '" & sodt & "')"
        Else
            sqlstr = "UPDATE NHANVIEN SET  MaNhanVien  = '" & manv & _
                                        "', TenNhanVien   = '" & tennv & _
                                        "', DiaChiNhanVien      = '" & diachi & _
                                        "',  DienThoaiNhanVien      = '" & sodt & _
                                    "' WHERE MaNhanVien  = '" & manv & "'"

        End If
        Return connect.Execute(sqlstr)
    End Function
    Public Function XoaNhanVien(ByVal emp As NhanVienDTO)
        Dim manv As String = emp.MaNhanVien()
        sqlstr = "DELETE NHANVIEN WHERE MaNhanVien = '" & manv & "'"
        Return connect.Execute(sqlstr)
    End Function


    Public Function GetData() As List(Of NhanVienDTO)
        Dim i As Integer
        Dim mnv, tNV, dcNV, sdt As String
        Dim nvDTO As NhanVienDTO
        Dim nvList As New List(Of NhanVienDTO)
        Dim dt As New DataTable
        dt = connect.GetData("select * from NHANVIEN")
        For i = 0 To dt.Rows.Count() - 1
            mnv = dt.Rows(i)("MaNhanVien").ToString
            tNV = dt.Rows(i)("TenNhanVien").ToString
            dcNV = dt.Rows(i)("DiaChiNhanVien").ToString
            sdt = dt.Rows(i)("DienThoaiNhanVien").ToString
            nvDTO = New NhanVienDTO(mnv, tNV, dcNV, sdt)
            nvList.Add(nvDTO)
        Next
        Return nvList
    End Function
End Class
